#ifndef MAPSMANAGER_H
#define MAPSMANAGER_H

#include <QtGui>

#include "controls/rotatingwidget.h"

#include "map.h"

class FTLabel;
class FTPushButton;
class FTPushButtonIcon;
class FTWidgetList;
class FTCheckBox;
class MapCalibrator;
class FTHelpWidget;

class MapsManager : public RotatingWidget
{
    Q_OBJECT
public:
    explicit MapsManager();

    bool mapsEnabled() const;

    void paintMap(QPainter&, const QTransform&, const QRectF&, double, double) const;

signals:
    void enableMaps(bool);

public slots:
    void invalidateBlocks();
    void requestEnableMap(bool);
    void toggleEnableMap();

private slots:
    void importNewMap();
    void sortMaps(QList<int>);
    void deleteMap(int);
    void editMap(int);
    void editMap(Map*);

private:

    QStackedWidget* pages;

    void buildMainPage();
    void buildEditPage();

    // Main page:
    FTPushButton* loadButton;
    FTPushButton* showButton;
    FTPushButton* enableosmButton;
    FTLabel* numMaps;
    FTWidgetList* mapsList;
    QWidget* mainPage;

    QLayout* createHorizontal();
    QLayout* createVertical();

private:
    void appendMap( Map* );

    QHash<int, Map*> bind_maps;
    QHash<int, FTLabel*> map_labels;

    QList<Map*> maps;

    QFile configFile;

    void saveConfigFile();

    void updateNumMaps();

    void createBlock( QPixmap&,const QRectF&, double, double ) const;


private slots:
    void saveEditMap();
    void cancelEditMap();
    void deleteMapUser();
    void loadCalibration();
    void openManualCalibration();
    void saveManualCalibration(QList<map_cal_point>);
    void closeManualCalibration();

private:
    // Edit page:
    QStackedWidget* editTabs;

    void updateCalibrateLabel();
    FTLabel* calibratedLabel;
    QWidget* editPage;
    FTLabel* titleLabel;
    QLineEdit* titleEdit;
    FTPushButton* saveButton;
    FTPushButton* cancelButton;
    FTPushButton* loadCalibrationButton;
    FTPushButton* calibrationButton;

    MapCalibrator* calibrator;


    FTCheckBox* enableMapButton;
    FTPushButtonIcon* deleteMapButton;

    Map* selectedMap;
    QList<map_cal_point> calibrationPoints;
};

#endif // MAPSMANAGER_H
